/** 
 * 
 * Licensed under the MIT License and Apache License version 2.0
 * 
 * Copyright (c) 2011 Jazz Digital (http://www.jazz.etc.br) 
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 * 
 * http://www.opensource.org/licenses/mit-license.php
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * http://code.google.com/p/kinect-jazztures/
 * 
 * @author Valério Oliveira (valck) - http://www.valck.in
 * @author João Marquesini - http://www.markezine.me
 * @author Gabriel Tavares de Souza - http://www.gtsouza.com
 * 
 */
package jazztures.events {

	import jazztures.objects.Skeleton;

	import flash.events.Event;
	
	/**
	 * 
	 * Creates an <code>SkeletonEvent</code> object to pass as a parameter to skeleton events listeners.
	 * 
	 */
	public class SkeletonEvent extends Event{
		
		public static const ADD_SKELETON : String = "add_skeleton";
		public static const UPDATE_SKELETON : String = "update_skeleton";
		public static const REMOVE_SKELETON : String = "remove_skeleton";

		private var _skeleton : Skeleton;
		private var _data : Object;
		private var _id : uint;
		

		/**
		 * 
		 * Creates an <code>SkeletonEvent</code> object to pass as a parameter to skeleton events listeners.
		 * 
		 * @param p_type The type of the event, accessible as SkeletonEvent.ADD_SKELETON, SkeletonEvent.UPDATE_SKELETON and SkeletonEvent.REMOVE_SKELETON.
		 * @param p_id The id (<code>uint</code>) received from the server.
		 * @param p_data The whole skeleton object received from the server.
		 * @param p_bubbles Determines whether the SkeletonEvent object participates in the bubbling stage of the event flow. The default value is <code>false</code>.
		 * @param p_cancelable Determines whether the SkeletonEvent object can be canceled. The default values is <code>false</code>. 
		 * 
		 */
		public function SkeletonEvent(p_type:String, p_id:uint, p_data:Object, p_bubbles:Boolean=false, p_cancelable:Boolean=false){
			_data = p_data;
			_id = p_id;
			_skeleton = new Skeleton(p_id, p_data.head, p_data.neck, p_data.torso, p_data.leftshoulder, p_data.rightshoulder, p_data.lefthip, p_data.righthip, p_data.leftknee, p_data.rightknee, p_data.leftfoot, p_data.rightfoot, p_data.leftelbow, p_data.rightelbow, p_data.lefthand, p_data.righthand);
			
			super(p_type, p_bubbles, p_cancelable);
		}
		
		/**
		 * 
		 * Indicates the id of the <code>User</code>.
		 * 
		 * @return <code>uint</code> 
		 * 
		 */
		public function get id():uint{
			return _id;
		}
		
		/**
		 * 
		 * Indicates the id of the <code>User</code>.
		 * 
		 * @param p_value The id (<code>uint</code>).
		 * 
		 */
		public function set id(p_value:uint):void{
			_id = p_value;
		}
				
		/**
		 *
		 * The data is the whole skeleton object received from the server.
		 *  
		 * @return <code>Object</code>
		 * 
		 */
		private function get data():Object{
			return _data;
		}
		
		/**
		 * 
		 * Is the data already parsed and encoded in <code>Skeleton</code> format.
		 * 
		 * @return <code>Skeleton</code>
		 * 
		 */
		public function get skeleton():Skeleton{
			return _skeleton;
		}
		
		/**
		 * 
		 * The new <code>SkeletonEvent</code> object includes all the properties of the original. 
		 * 
		 * @return <code>SkeletonEvent</code>
		 * 
		 */
		public override function clone():Event{
			return new SkeletonEvent(type, id, data, bubbles, cancelable);
		}
		
		/**
		 * 
		 * Returns a string containing all the properties of the <code>SkeletonEvent</code> object.
		 * 
		 * @return The string is in the following format: [SkeletonEvent type=value id=value data=value bubbles=value cancelable=value]
		 * 
		 */
		public override function toString():String{
			return formatToString("SkeletonEvent", "type", "id", "data", "bubbles", "cancelable");
		}
	}
}